package com.ruoyi.financial.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.financial.bo.SettingCustOddsBo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.financial.domain.FOddsRule;
import com.ruoyi.financial.service.IFOddsRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 赔付规则Controller
 *
 * @author ruoyi
 * @date 2025-02-06
 */
@RestController
@RequestMapping("/financial/rule")
public class FOddsRuleController extends BaseController {
    @Autowired
    private IFOddsRuleService fOddsRuleService;

    /**
     * 查询赔付规则列表
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(FOddsRule fOddsRule) {
        startPage();
        List<FOddsRule> list = fOddsRuleService.selectFOddsRuleList(fOddsRule);
        return getDataTable(list);
    }

    /**
     * 导出赔付规则列表
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:export')")
    @Log(title = "赔付规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FOddsRule fOddsRule) {
        List<FOddsRule> list = fOddsRuleService.selectFOddsRuleList(fOddsRule);
        ExcelUtil<FOddsRule> util = new ExcelUtil<FOddsRule>(FOddsRule.class);
        util.exportExcel(response, list, "赔付规则数据");
    }

    /**
     * 获取赔付规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fOddsRuleService.selectFOddsRuleById(id));
    }

    /**
     * 新增赔付规则
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:add')")
    @Log(title = "赔付规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FOddsRule fOddsRule) {
        return toAjax(fOddsRuleService.insertFOddsRule(fOddsRule));
    }

    /**
     * 修改赔付规则
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:edit')")
    @Log(title = "赔付规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FOddsRule fOddsRule) {
        return toAjax(fOddsRuleService.updateFOddsRule(fOddsRule));
    }

    /**
     * 删除赔付规则
     */
    @PreAuthorize("@ss.hasPermi('financial:rule:remove')")
    @Log(title = "赔付规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fOddsRuleService.deleteFOddsRuleByIds(ids));
    }


    @GetMapping("/custOddsList")
    public R<Map<String, Object>> custOddsList(@RequestParam("custId") Long custId,
                                               @RequestParam("bankerId") Long bankerId,
                                               @RequestParam("custType") Integer custType
    ) {
        Map<String, Object> result = fOddsRuleService.custOddsList(bankerId, custId,custType);
        return R.ok(result);
    }


    @PostMapping("/settingCustOdds")
    public R settingCustOdds(@RequestBody SettingCustOddsBo bo) {
        fOddsRuleService.settingCustOdds(bo);
        return R.ok();
    }
}
